// 引入路由静态路由 动态路由
import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  // 权限菜单name
  routes: []
}
const mutations = {
  setRouter(store, data) {
    // 首页和新权限菜单路由拼接
    store.routes = [
      ...constantRoutes,
      ...data
    ]
  }
}
const actions = {
  filterRouter(store, menus) {
    // 过滤权限
    const newAsyncRouter = asyncRoutes
      .filter(item => menus.includes(item.name))
    // 动态菜单名称修改
    store.commit('setRouter', newAsyncRouter)
    // 导出新权限
    return newAsyncRouter
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
